/**
 * 
 */
package com.teamall.web.xtgl.controller;

import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import com.teamall.core.common.JModelAndView;
import com.teamall.core.common.Page;
import com.teamall.core.excel.ExcelUtils;
import com.teamall.framework.exception.BaseAppException;
import com.teamall.framework.log.LogManager;
import com.teamall.framework.util.DateUtils;
import com.teamall.framework.util.ImportExcelUtils;
import com.teamall.framework.util.Utils;
import com.teamall.web.base.db.po.TownInfoPO;
import com.teamall.web.base.db.po.VillageInfoPO;
import com.teamall.web.base.service.ITownInfoService;
import com.teamall.web.base.service.IVillageInfoService;
import com.teamall.web.base.vo.ResultVO;
import com.teamall.web.family.db.po.FamilyInfoPO;
import com.teamall.web.family.db.po.FamilyMemberPO;
import com.teamall.web.family.db.po.ProjectFamilyRelatedPO;
import com.teamall.web.family.service.IFamilyInfoService;
import com.teamall.web.family.service.IFamilyMemberService;
import com.teamall.web.family.service.IProjectFamilyRelatedService;
import com.teamall.web.fpgz.db.po.CodeFamilyInfoPO;
import com.teamall.web.fpxm.db.po.AidProjectPO;
import com.teamall.web.fpxm.db.po.CodeAidProjectPO;
import com.teamall.web.fpxm.service.IAidProjectService;
import com.teamall.web.fpxm.service.ICodeAidProjectService;
import com.teamall.web.sys.db.po.DataDictPO;
import com.teamall.web.sys.service.IDataDictService;
import com.teamall.web.xtgl.common.ImpDataResultVO;
import com.teamall.web.xtgl.common.StaticDataUtil;
import com.teamall.web.xtgl.db.po.CodeFamilyMemberToImprPO;
import com.teamall.web.xtgl.service.IBasicDataService;
import com.teamall.web.xtgl.service.ICodeFamilyMemberToImprService;
import com.teamall.web.xxgl.db.po.AidReportChannelPO;
import com.teamall.web.xxgl.db.po.AidReportChannelRelPO;
import com.teamall.web.xxgl.service.IAidReportChannelRelService;
import com.teamall.web.xxgl.service.IAidReportChannelService;

/**
 * <Description>基础数据 <br>
 * 
 * @author pan.xiaobo<br>
 * @version 1.0<br>
 * @taskId <br>
 * @CreateDate 2017年8月15日 <br>
 * @since V1.0<br>
 * @see com.teamall.web.xtgl.controller <br>
 */
@Controller
@RequestMapping("/basicData")
public class BasicDataController {
    private static final LogManager logger = LogManager
            .getLogger(BasicDataController.class);

    public static final String ACTION_ADD = "add";

    public static final String ACTION_UPDATE = "update";

    public static final String ACTION_DELETE = "delete";

    @Autowired
    private ITownInfoService townInfoService;

    @Autowired
    private IVillageInfoService villageInfoService;

    @Autowired
    private ICodeFamilyMemberToImprService codeFamilyMemberToImprService;

    @Autowired
    private IBasicDataService basicDataService;

    @Autowired
    private IFamilyInfoService familyInfoService;

    @Autowired
    private IFamilyMemberService familyMemberService;

    @Autowired
    private ICodeAidProjectService codeAidProjectService;

    @Autowired
    private IAidProjectService aidProjectService;

    @Autowired
    private IDataDictService dataDictService;

    @Autowired
    private IProjectFamilyRelatedService projectFamilyRelatedService;

    @Autowired
    private IAidReportChannelService aidReportChannelService;

    @Autowired
    private IAidReportChannelRelService aidReportChannelRelService;

    /**
     * 贫困户信息主页
     * 
     * @return
     * @throws BaseAppException
     */
    @RequestMapping("/familyIndex")
    public ModelAndView familyIndex() throws BaseAppException {

        ModelAndView modelAndView = new JModelAndView("/xtgl/family_main");
        List<TownInfoPO> townInfoPOList = townInfoService
                .selectByArg(new TownInfoPO());
        List<VillageInfoPO> villageInfoPOList = villageInfoService
                .selectByArg(new VillageInfoPO());
        for (TownInfoPO townInfoPO : townInfoPOList) {
            for (VillageInfoPO villageInfoPO : villageInfoPOList) {
                if (townInfoPO.getTownId() == villageInfoPO.getTownId()) {
                    townInfoPO.getVillageInfoPOList().add(villageInfoPO);
                }
            }
        }

        modelAndView.addObject("townInfoPOList", townInfoPOList);
        return modelAndView;
    }

    /**
     * 上传excel
     * 
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/uploadFamilyExcel", method = {
        RequestMethod.POST
    })
    public ModelAndView uploadFamilyExcel(HttpServletRequest request)
            throws Exception {
        ModelAndView modelAndView = familyIndex();
        InputStream onein = null;
        InputStream twoin = null;
        List<List<Object>> listob = null;
        try {
            MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
            System.out.println("通过传统方式form表单提交方式导入excel文件！");

            MultipartFile file = multipartRequest.getFile("upfile");
            if (file.isEmpty()) {
                throw new Exception("文件不存在！");
            }
            String fileName = file.getOriginalFilename();
            if (!".xls".equals(fileName.substring(fileName.lastIndexOf(".")))
                    && !".xlsx".equals(fileName.substring(fileName
                            .lastIndexOf(".")))) {
                throw new Exception("请选择Excel格式的文件导入！");
            }
            onein = file.getInputStream();
            checkExcel(onein, file.getOriginalFilename(), 0);
            onein.close();

            twoin = file.getInputStream();
            listob = new ImportExcelUtils().getSheetDataListByExcel(twoin,
                    file.getOriginalFilename(), 0);
            twoin.close();

            ImpDataResultVO resultVO = basicDataService
                    .upInsertFamilyAndMember(listob);
            modelAndView.addObject("resultVO", resultVO);
        }
        catch (Exception e) {
            ImpDataResultVO resultVO = new ImpDataResultVO();
            resultVO.setCode(999);
            resultVO.setErrorMsg(e.getMessage());
            modelAndView.addObject("resultVO", resultVO);
        }
        finally {
            try {
                if (onein != null)
                    onein.close();
            }
            catch (Exception e) {
            }
            try {
                if (twoin != null)
                    twoin.close();
            }
            catch (Exception e) {
            }
        }

        return modelAndView;
    }

    private void checkExcel(InputStream in, String fileName, int sheetNum)
            throws Exception {
        // 创建Excel工作薄
        Workbook work = new ImportExcelUtils().getWorkbook(in, fileName);
        if (null == work) {
            throw new Exception("该Excel工作薄为空！");
        }
        Sheet sheet = work.getSheetAt(sheetNum);
        if (sheet == null) {
            throw new Exception("该Excel工作薄的工作表为空！");
        }
        if (sheet.getLastRowNum() < 2) {
            throw new Exception("该Excel工作薄的工作表为空！");
        }
        Row row = sheet.getRow(2);
        if (row.getLastCellNum() != 29) {
            throw new Exception("该Excel工作薄的列数不对，请按模板填写！");
        }
    }

    /**
     * 导出excel
     * 
     * @param response
     * @param qryRecord
     * @throws Exception
     */
    @RequestMapping("doExcelExport")
    public void doExcelExport(HttpServletResponse response,
            CodeFamilyMemberToImprPO qryRecord) throws Exception {
        logger.debug(qryRecord.toString());
        // 对中文进行转码
        if (Utils.notEmpty(qryRecord.getName())) {
            qryRecord.setName(java.net.URLDecoder.decode(qryRecord.getName(),
                    "UTF-8"));
            logger.debug(qryRecord.toString());
        }

        List<CodeFamilyMemberToImprPO> resultList = codeFamilyMemberToImprService
                .selectByArg(qryRecord);
        if (null == resultList || resultList.size() == 0) {

        }
        for (CodeFamilyMemberToImprPO one : resultList) {
            one.setProvinceName("内蒙古自治区");
            one.setCityName("锡林郭勒盟");
            one.setCountryName("苏尼特右旗");
        }

        // 数据中的key
        String keys[] = {
                "provinceName", "cityName", "countryName", "townName",
                "villageName", "familyCode", "personCode", "name",
                "genderName", "idNumber", "personNum", "masterRelName",
                "nationName", "educationLevelName", "studentStateName",
                "healthStateName", "workSkillName", "workStateName",
                "workMonths", "isNrcmsName", "isEndowmentName",
                "isCityEndowmentName", "povertyStateName", "povertyAttrName",
                "mainReasonName", "avgIncome", "tel", "bankName", "accountCode"
        };

        Workbook wb = null;
        OutputStream ouputStream = null;
        try {

            String tplPath = BasicDataController.class.getClassLoader()
                    .getResource("").getPath()
                    + "tpl_familyInfo.xls";
            logger.info(""
                    + BasicDataController.class.getClassLoader()
                            .getResource("").getPath());
            logger.info("excel模板路径：" + tplPath);
            wb = ExcelUtils.createWorkBookByTpl(new File(tplPath), 2, 0,
                    resultList, keys, keys);
            response.setContentType("application/vnd.ms-excel");
            response.setHeader(
                    "Content-Disposition",
                    "attachment;filename="
                            + new String(
                                    ("贫困户信息_" + DateUtils.getCurrentDate() + ".xls")
                                            .getBytes(), "iso-8859-1"));
            ouputStream = response.getOutputStream();
            wb.write(ouputStream);
            ouputStream.flush();
            // ouputStream.close();
        }
        catch (Exception e) {
            logger.error("导出Excel时发生异常：" + e.getMessage(), e);
        }
        finally {
            try {
                if (ouputStream != null)
                    ouputStream.close();
            }
            catch (Exception e) {
                logger.error("导出Excel关闭流抛异常：", e);
            }
        }
    }

    /**
     * 查询贫困家庭及其成员列表
     * 
     * @param qryRecord
     * @param resultPage
     * @return
     * @throws BaseAppException
     */
    @RequestMapping("/qryFamilyAndMembers")
    @ResponseBody
    public Page<CodeFamilyMemberToImprPO> qryFamilyAndMembers(
            CodeFamilyMemberToImprPO qryRecord,
            Page<CodeFamilyMemberToImprPO> resultPage) throws BaseAppException {
        // 查詢条件：村id,贫困户名等
        resultPage = codeFamilyMemberToImprService.selectByArgAndPage(
                qryRecord, resultPage);
        return resultPage;
    }

    /**
     * 查询贫困家庭及其成员详情，供修改
     * 
     * @param qryRecord
     * @param rowId
     * @return
     * @throws BaseAppException
     */
    @RequestMapping("/familyDetail")
    public ModelAndView familyDetail(CodeFamilyMemberToImprPO qryRecord,
            String rowId) throws BaseAppException {

        ModelAndView modelAndView = new JModelAndView("/xtgl/family_detail");
        List<CodeFamilyMemberToImprPO> familyAndMemberPOList = codeFamilyMemberToImprService
                .selectByArg(qryRecord);
        if (null == familyAndMemberPOList || familyAndMemberPOList.size() == 0) {
            modelAndView.addObject("hasData", false);
        }
        else {
            modelAndView.addObject("hasData", true);
            modelAndView.addObject("familyAndMemberPO",
                    familyAndMemberPOList.get(0));
        }

        modelAndView.addObject("genderNameMap", StaticDataUtil.genderNameMap);
        modelAndView.addObject("masterRelNameMap",
                StaticDataUtil.masterRelNameMap);
        modelAndView.addObject("nationNameMap", StaticDataUtil.nationNameMap);
        modelAndView.addObject("educationLevelNameMap",
                StaticDataUtil.educationLevelNameMap);
        modelAndView.addObject("studentStateNameMap",
                StaticDataUtil.studentStateNameMap);
        modelAndView.addObject("healthStateNameMap",
                StaticDataUtil.healthStateNameMap);
        modelAndView.addObject("workSkillNameMap",
                StaticDataUtil.workSkillNameMap);
        modelAndView.addObject("workStateNameMap",
                StaticDataUtil.workStateNameMap);
        modelAndView.addObject("povertyStateNameMap",
                StaticDataUtil.povertyStateNameMap);
        modelAndView.addObject("povertyAttrNameMap",
                StaticDataUtil.povertyAttrNameMap);
        modelAndView.addObject("mainReasonNameMap",
                StaticDataUtil.mainReasonNameMap);
        modelAndView.addObject("editRowId", rowId);

        return modelAndView;
    }

    /**
     * 修改贫困家庭及其成员详情
     * 
     * @param record
     * @return
     * @throws BaseAppException
     */
    @RequestMapping("/updateFamilyDetail")
    @ResponseBody
    public CodeFamilyMemberToImprPO updateFamilyDetail(
            FamilyInfoPO familyInfoPO, FamilyMemberPO familyMemberPO,
            String povertyYear) throws BaseAppException {
        if (Utils.notEmpty(povertyYear)) {
            familyInfoPO.setPovertyStateDate(DateUtils.string2Date(povertyYear,
                    DateUtils.STR_DATE_FORMAT_YEAR));
        }

        basicDataService.updateFamilyInfo(familyInfoPO);
        basicDataService.updateFamilyMember(familyMemberPO);

        FamilyMemberPO tmpPO = familyMemberService
                .selectByPrimaryKey(familyMemberPO.getFamilyMemeberId());
        CodeFamilyMemberToImprPO resultPO = codeFamilyMemberToImprService
                .selectByPrimaryKey(tmpPO.getIdNumber() + "_"
                        + familyMemberPO.getFamilyMemeberId());

        return resultPO;
    }

    /**
     * 删除家庭成员
     * 
     * @param ids
     * @return
     * @throws BaseAppException
     */
    @RequestMapping("/deleteFamilyMembers")
    @ResponseBody
    public ResultVO deleteFamilyMembers(String ids) throws BaseAppException {
        ResultVO resultVO = new ResultVO();
        String[] idArray = ids.split(",");
        try {
            for (String id : idArray) {
                FamilyMemberPO delPO = new FamilyMemberPO();
                delPO.setFamilyMemeberId(Integer.parseInt(id));
                familyMemberService.delete(delPO);
            }
            resultVO.setRspData(idArray.length);
        }
        catch (Exception e) {
            logger.equals(e);
            resultVO.setCode(999);
            resultVO.setMsg(e.getMessage());
            resultVO.setRspData("");
            return resultVO;
        }

        return resultVO;
    }

    /**
     * 项目基本信息
     * 
     * @return
     * @throws BaseAppException
     */
    @RequestMapping("/projectIndex")
    public ModelAndView projectIndex() throws BaseAppException {

        ModelAndView modelAndView = new JModelAndView("/xtgl/project_main");

        // 项目分类
        DataDictPO qryDataDict = new DataDictPO();
        qryDataDict.setDataGroup(300);
        List<DataDictPO> projectTypeList = dataDictService
                .selectByArg(qryDataDict);

        modelAndView.addObject("projectTypeList", projectTypeList);

        return modelAndView;
    }

    @ResponseBody
    @RequestMapping("/qryProjectByPage")
    public Page<CodeAidProjectPO> qryProjectByPage(CodeAidProjectPO po,
            Page<CodeAidProjectPO> resultPage) throws BaseAppException {
        resultPage = codeAidProjectService.selectByArgAndPage(po, resultPage);
        return resultPage;
    }

    /**
     * 项目信息编辑
     * 
     * @param qryRecord
     * @param rowId
     * @return
     * @throws BaseAppException
     */
    @RequestMapping("/projectDetail")
    public ModelAndView projectDetail(CodeAidProjectPO qryRecord,
            String editRowId, String action) throws BaseAppException {

        ModelAndView modelAndView = new JModelAndView("/xtgl/project_detail");
        modelAndView.addObject("editRowId", editRowId);
        modelAndView.addObject("action", action);

        if (ACTION_UPDATE.equals(action)) {
            List<CodeAidProjectPO> aidProjectList = codeAidProjectService
                    .selectByArg(qryRecord);

            if (null == aidProjectList || aidProjectList.size() == 0) {
                modelAndView.addObject("hasData", false);
            }
            else {
                modelAndView.addObject("hasData", true);
                modelAndView.addObject("aidProjectPO", aidProjectList.get(0));
            }
        }
        else {
            CodeAidProjectPO po = new CodeAidProjectPO();
            po.setProjectId(-1);
            modelAndView.addObject("aidProjectPO", po);
        }

        // 项目分类
        DataDictPO qryDataDict = new DataDictPO();
        qryDataDict.setDataGroup(300);
        List<DataDictPO> projectTypeList = dataDictService
                .selectByArg(qryDataDict);
        modelAndView.addObject("projectTypeList", projectTypeList);

        // 项目子类型
        qryDataDict.setDataGroup(301);
        List<DataDictPO> projectSubTypeList = dataDictService
                .selectByArg(qryDataDict);
        modelAndView.addObject("projectSubTypeList", projectSubTypeList);

        // 项目状态
        qryDataDict.setDataGroup(302);
        List<DataDictPO> projectStateList = dataDictService
                .selectByArg(qryDataDict);
        modelAndView.addObject("projectStateList", projectStateList);

        // 镇
        List<TownInfoPO> townInfoPOList = townInfoService
                .selectByArg(new TownInfoPO());
        List<VillageInfoPO> villageInfoPOList = villageInfoService
                .selectByArg(new VillageInfoPO());
        for (TownInfoPO townInfoPO : townInfoPOList) {
            for (VillageInfoPO villageInfoPO : villageInfoPOList) {
                if (townInfoPO.getTownId() == villageInfoPO.getTownId()) {
                    townInfoPO.getVillageInfoPOList().add(villageInfoPO);
                }
            }
        }
        modelAndView.addObject("townInfoPOList", townInfoPOList);

        return modelAndView;
    }

    @RequestMapping("/updateProjectDetail")
    @ResponseBody
    public ResultVO updateProjectDetail(AidProjectPO aidProjectPO, String action)
            throws BaseAppException {
        ResultVO resultVO = new ResultVO();
        try {
            if (ACTION_ADD.equals(action)) {
                int pkId = aidProjectService.add(aidProjectPO);
                aidProjectPO.setProjectId(pkId);

            }

            if (ACTION_UPDATE.equals(action)) {
                aidProjectService.updateByPrimaryKey(aidProjectPO);
            }
        }
        catch (Exception e) {
            logger.equals(e);
            resultVO.setCode(999);
            resultVO.setMsg(e.getMessage());
            return resultVO;
        }

        resultVO.setRspData(aidProjectPO);
        return resultVO;
    }

    /**
     * 查询贫困户列表
     * 
     * @param qryRecord
     * @param resultPage
     * @return
     * @throws BaseAppException
     */
    @RequestMapping("/qryFamilyInfo")
    @ResponseBody
    public Page<CodeFamilyInfoPO> qryFamilyInfo(CodeFamilyInfoPO qryRecord,
            Page<CodeFamilyInfoPO> resultPage, Integer projectId,
            boolean isInclude) throws BaseAppException {
        if (null == projectId)
            projectId = -1;
        // 查詢条件：村id,贫困户名等
        resultPage = basicDataService.selectCodeFamilyInfoPOByArgAndPage(
                qryRecord, resultPage, isInclude, projectId);
        return resultPage;
    }

    @RequestMapping("/updateRelated")
    @ResponseBody
    public ResultVO updateRelated(Integer projectId, String ids, String action) {
        ResultVO resultVO = new ResultVO();
        String[] idArray = ids.split(",");
        if (ACTION_ADD.equals(action)) {
            try {
                List<ProjectFamilyRelatedPO> records = new ArrayList<ProjectFamilyRelatedPO>();
                for (String id : idArray) {
                    ProjectFamilyRelatedPO po = new ProjectFamilyRelatedPO();
                    po.setFamilyId(Integer.parseInt(id));
                    po.setProjectId(projectId);
                    records.add(po);
                }

                projectFamilyRelatedService.addBatch(records);
            }
            catch (BaseAppException e) {
                logger.equals(e);
                resultVO.setCode(999);
                resultVO.setMsg(e.getMessage());
                return resultVO;
            }
        }

        if (ACTION_DELETE.equals(action)) {
            try {
                Integer[] familyIds = new Integer[idArray.length];
                for (int i = 0; i < idArray.length; i++) {
                    familyIds[i] = Integer.parseInt(idArray[i]);
                }

                projectFamilyRelatedService.deleteByBatch(projectId, familyIds);
            }
            catch (BaseAppException e) {
                logger.equals(e);
                resultVO.setCode(999);
                resultVO.setMsg(e.getMessage());
                return resultVO;
            }
        }

        return resultVO;
    }

    /**
     * 跳转到待绑定贫困户列表
     * 
     * @return
     * @throws BaseAppException
     */
    @RequestMapping("/projectUnRelated")
    public ModelAndView projectUnRelated() throws BaseAppException {

        ModelAndView modelAndView = new JModelAndView(
                "/xtgl/project_family_doRelated");
        // 镇
        List<TownInfoPO> townInfoPOList = townInfoService
                .selectByArg(new TownInfoPO());
        List<VillageInfoPO> villageInfoPOList = villageInfoService
                .selectByArg(new VillageInfoPO());
        for (TownInfoPO townInfoPO : townInfoPOList) {
            for (VillageInfoPO villageInfoPO : villageInfoPOList) {
                if (townInfoPO.getTownId() == villageInfoPO.getTownId()) {
                    townInfoPO.getVillageInfoPOList().add(villageInfoPO);
                }
            }
        }
        modelAndView.addObject("townInfoPOList", townInfoPOList);
        return modelAndView;
    }

    /**
     * 信息报送，引用单位维护
     * 
     * @return
     * @throws BaseAppException
     */
    @RequestMapping("/aidReportChannelIndex")
    public ModelAndView aidReportChannelIndex() throws BaseAppException {

        ModelAndView modelAndView = new JModelAndView(
                "/xtgl/aidReportChannel_main");
        return modelAndView;
    }

    @RequestMapping("/aidReportChannelDetail")
    public ModelAndView aidReportChannelDetail(String channelId, String action)
            throws BaseAppException {

        ModelAndView modelAndView = new JModelAndView(
                "/xtgl/aidReportChannel_detail");
        AidReportChannelPO record = new AidReportChannelPO();

        if (ACTION_UPDATE.equals(action)) {
            record = aidReportChannelService.selectByPrimaryKey(Integer
                    .parseInt(channelId));
        }
        modelAndView.addObject("action", action);
        modelAndView.addObject("aidReportChannelPO", record);

        return modelAndView;
    }

    @RequestMapping("qryAidReportChannel")
    @ResponseBody
    public Page<AidReportChannelPO> qryAidReportChannel(
            AidReportChannelPO record, Page<AidReportChannelPO> resultPage)
            throws BaseAppException {
        resultPage = aidReportChannelService.selectByArgAndPage(record,
                resultPage);
        return resultPage;
    }

    @RequestMapping("updateAidReportChannel")
    @ResponseBody
    public ResultVO updateAidReportChannel(AidReportChannelPO record,
            String action) throws BaseAppException {
        ResultVO resultVO = new ResultVO();
        try {
            if (ACTION_ADD.equals(action)) {
                int pkId = aidReportChannelService.add(record);
                record.setChannelId(pkId);

            }

            if (ACTION_UPDATE.equals(action)) {
                aidReportChannelService.update(record);
            }
        }
        catch (Exception e) {
            logger.equals(e);
            resultVO.setCode(999);
            resultVO.setMsg(e.getMessage());
            return resultVO;
        }

        resultVO.setRspData(record);
        return resultVO;
    }

    @RequestMapping("deleteAidReportChannel")
    @ResponseBody
    public ResultVO deleteAidReportChannel(AidReportChannelPO record)
            throws BaseAppException {
        ResultVO resultVO = new ResultVO();
        try {
            AidReportChannelRelPO qryRel = new AidReportChannelRelPO();
            qryRel.setChannelId(record.getChannelId());
            List<AidReportChannelRelPO> relList = aidReportChannelRelService
                    .selectByArg(qryRel);
            if (null != relList && relList.size() > 0) {
                resultVO.setCode(1);
                resultVO.setMsg("已存在关联的信息报送记录，不能删除");
                return resultVO;
            }
            aidReportChannelService.delete(record);
        }
        catch (Exception e) {
            logger.equals(e);
            resultVO.setCode(999);
            resultVO.setMsg("发生异常！");
            return resultVO;
        }
        return resultVO;
    }
}
